package com.hitqz.robot.biz.controller;

import cn.hutool.extra.spring.SpringUtil;
import com.hitqz.robot.api.business.dto.RobotSendClientMsgDto;
import com.hitqz.robot.api.dispatch.protocol.ProtocolEnum;
import com.hitqz.robot.camera.dto.RealManArmMoveDto;
import com.hitqz.robot.common.core.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("/realManArm")
@Tag(name = "瑞尔曼机械臂控制管理")
public class RealManArmController {


    @PostMapping("/{clientId}/setZeroPoint")
    @Operation(summary = "设置零点")
    public R<Void> setZeroPoint(@PathVariable(value = "clientId") String clientId) {
        RobotSendClientMsgDto dto = new RobotSendClientMsgDto();
        dto.setClientId(clientId);
        dto.setCmd((int) ProtocolEnum.ROBOT_REAL_MAN_ARM_SET_ZERO_POINT.getCmd());
        SpringUtil.getApplicationContext().publishEvent(dto);
        return R.ok();
    }

    @PostMapping("/{clientId}/turnZeroPoint")
    @Operation(summary = "转向零点")
    public R<Void> turnZeroPoint(@PathVariable(value = "clientId") String clientId) {
        RobotSendClientMsgDto dto = new RobotSendClientMsgDto();
        dto.setClientId(clientId);
        dto.setCmd((int) ProtocolEnum.ROBOT_REAL_MAN_ARM_TURN_ZERO_POINT.getCmd());
        SpringUtil.getApplicationContext().publishEvent(dto);
        return R.ok();
    }

    @PostMapping("/{clientId}/emergencyStopRecovery")
    @Operation(summary = "急停恢复")
    public R<Void> emergencyStopRecovery(@PathVariable(value = "clientId") String clientId) {
        RobotSendClientMsgDto dto = new RobotSendClientMsgDto();
        dto.setClientId(clientId);
        dto.setCmd((int) ProtocolEnum.ROBOT_REAL_MAN_ARM_RECOVERY.getCmd());
        SpringUtil.getApplicationContext().publishEvent(dto);
        return R.ok();
    }

    @PostMapping("/{clientId}/move")
    @Operation(summary = "关节运动")
    public R<Void> move(@PathVariable(value = "clientId") String clientId, @RequestBody RealManArmMoveDto moveDto) {
        RobotSendClientMsgDto dto = new RobotSendClientMsgDto();
        dto.setClientId(clientId);
        dto.setCmd((int) ProtocolEnum.ROBOT_REAL_MAN_ARM_MOVE.getCmd());
        dto.setData(moveDto);
        SpringUtil.getApplicationContext().publishEvent(dto);
        return R.ok();
    }
}
